package repo

import (
	model "micro-oauth/datamodels"
	"micro-oauth/datamodels/params"
)

type ServiceInterface interface {
	MigrateTables() error
	// partner related
	GetPartnerById(partnerId uint64) *model.Partner
	DeletePartner(partnerId uint64) error
	AddPartner(partner *model.Partner) error
	UpdatePartner(partner *model.Partner) error
	ListPartner(req *params.PartnerListRequest) (partners []*model.Partner, total uint64, err error)

	// scope related
	GetScopeById(scopeId uint64) *model.Scope
	AddScope(scope *model.Scope) error
	ListScope(req *params.ScopeListRequest) (scopes []*model.Scope, total uint64, err error)
	UpdateScope(scope *model.Scope) error
	DeleteScope(scopeId uint64) error

	// user related
	GetUserById(userId uint64) *model.User
	GetUserByIdFromDB(userId uint64) *model.User
	GetUserByMailFromDB(mail string) *model.User
	AddUser(user *model.User) error
	ListUser(req *params.UserListRequest) (users []*model.User, total uint64, err error) // /users/
	ListVendorUser(req *params.VendorUserListRequest) (users []*model.User, total uint64, err error)
	UpdateUser(user *model.User) error
	ListAdminUser(req *params.UserListRequest) (users []*model.User, total uint64, err error)
	DeleteUser(userId uint64) error
	GetUserByName(partnerId uint64, scopeId uint64, name string) *model.User // TODO: add scope
	GetUserRoles(partnerId, userId uint64) []*model.Role
	GetUserRoleIds(userId uint64) []uint64
	ReplaceUserRoles(user *model.User, roles []*model.Role) error

	// role related
	AddRole(role *model.Role) error
	GetRoleById(roleId uint64) *model.Role
	DeleteRole(roleId uint64) error
	UpdateRole(role *model.Role) error
	ListRoles(req *params.RoleListRequest) (roles []*model.Role, total uint64, err error)
	GetRoleByLan(lanType,name string) *model.Role

	ReplaceRolePermissionInfos(role *model.Role, permissions []*model.RolePermissionInfo) error
	ListRolePermissionInfos(roleId uint64) ([]*model.RolePermissionInfo, error)
	GetUserDetailData(partnerId, userId uint64) (userDetail *model.UserDetailData, err error)
	GetUserDetailFromRDB(partnerId, userId uint64) (user *model.User, err error)

	// client related
	GetClientById(clientId string) *model.Client
	GetClientByPrimaryId(clientId uint64) *model.Client
	GetPosClientByTerminalId(terminalId uint64) *model.Client
	AddClient(client *model.Client) error
	ListClient(req *params.ClientListRequest) (clients []*model.Client, total uint64, err error)
	UpdateClient(client *model.Client) error
	DeleteClient(clientId uint64) error

	// permission related
	ListPermissions(req *params.PermissionListRequest) (permissions []*model.Permission, total uint64, err error)
	ListRolePermissionCodes(roleIds []uint64) (permissionCodes []string, err error)
	AddPermission(req *model.Permission) error
	CheckAPIPermission(partnerId, userId uint64, apiCode string) (bool, error)
	GetPermissionById(pId uint64) *model.Permission
	UpdatePermission(permission *model.Permission) error
	ReplacePermissionAPIs(permission *model.Permission, apis []*model.API) error
	DeletePermission(permissionId uint64) error
	GetPermissionByLan(lanType,name string) *model.Permission
	ListPermissionMethod(partnerId uint64)([]*model.Method,error)
	DeletePermissionMethodByService(partnerId,scopeId uint64,serviceName string)error
	BatchAddPermissionMethod(partnerId uint64,serviceName string,methodList []*model.Method)error

	// API related
	AddAPI(req *model.API) error
	ListAPIs(req *params.APIListRequest) (apis []*model.API, total uint64, err error)
	GetAPIById(apiId uint64) *model.API
	UpdateAPI(api *model.API) error
	DeleteAPI(apiId uint64) error

	// token related
	AddToken(token *model.Token) error
	GetToken(accessToken string) *model.Token
	GetAuthUserInfo(accessToken string) (*model.UserInfo, error)
	DeleteToken(tokenId uint64) error
	ListToken(req *params.TokenListRequest) ([]*model.Token, error)
	DeleteTokens(opt *params.DeleteTokenOption) error
	UpdateToken(token *model.Token) error

	// device related
	GetDeviceByUUID(uuid string) *model.Device
	GetDeviceById(id uint64) *model.Device
	AddDevice(device *model.Device) error
	UpdateDevice(device *model.Device) error
	DeleteDevice(deviceId uint64) error
	ListDevice(partnerId, scopeId uint64, req *params.DeviceListRequest) (devices []*model.Device, total uint64, err error)
	Close()

	// user password rule
	CreatePasswordRule(rule *model.PassWordRule)error
	GetPasswordRule()(*model.PassWordRule,error)
	UpdatePasswordRule(ruleId uint64,rule *model.PassWordRule)(bool,error)


}
